import { useLocation } from 'react-router-dom';

/**
 * 根据URL获取菜单的选中菜单Key
 */
const useSelectedMenuKey = (): string[] => {
  const { pathname } = useLocation();
  let paths = pathname.split('/').filter((l) => l !== '');
  // 默认选中首页
  if (paths.length === 0) {
    paths = ['home'];
  }
  return [paths[0]];
};

export default useSelectedMenuKey;
